import { createRouter, createWebHistory } from 'vue-router'
import { constantRoute, routeWhiteList } from './routes.js'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [...constantRoute],
  // 滚动
  scrollBehavior() {
    return { left: 0, top: 0 }
  }
})

// 重置路由方法
export function resetRouter() {
  //获取所有路由
  router.getRoutes().forEach((route) => {
    const { name } = route //获取路由name
    if (name && !routeWhiteList.includes(name)) {
      //路由不属于白名单,则删除
      router.hasRoute(name) && router.removeRoute(name)
    }
  })
}

export default router
